package com.sping_boot3.spirng_boot3.controller;

import jakarta.annotation.Resource;

import org.springframework.data.redis.connection.BitFieldSubCommands;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

@RestController
public class RedisController {
    @Resource
    private RedisTemplate stringRedisTemplate;

    @GetMapping("/get")
    public String get() {
        // 组合成key= sign:userId:年月
        String key = buildSignKey(1234, LocalDate.now());
        // 获取当前日期是当月的第多少天
        LocalDate now = LocalDate.now();
        int dayOfMonth = now.getDayOfMonth();
        // 存到redis中的bitmap中，由于bitmap从0开始，第多少天从1开始，dayOfMonth需要减1
        stringRedisTemplate.opsForValue().setBit(key, dayOfMonth - 1, true);

        return "ok";
    }

    private static String buildSignKey(int uid, LocalDate date) {
        return String.format("sign:%s:%s", uid, formatDate(date));
    }

    /**
     * 日期格式化
     *
     * @param date
     * @return
     */
    private static String formatDate(LocalDate date) {
        return "20241112";
    }

    public static void main(String[] args) {

        Set<Object> strings = new HashSet<>();
        strings.add("你好0");
        strings.add("你好1");
        strings.add("你好2");


    }

}
